package com.seek.service.imp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONObject;
import com.seek.core.BaseServiceImpl;
import com.seek.dao.ConfigDao;
import com.seek.model.entity.TConfig;
import com.seek.service.ConfigService;
import com.seek.util.CommonUtil;
import com.seek.util.ConstantsUtil;

@Repository("configService")
public class ConfigServiceImpl extends BaseServiceImpl<TConfig> implements ConfigService {

	@Autowired
	public void setDao(ConfigDao configDao) {
		super.setDao(configDao);
	}
	public ConfigDao getDao() {
		return (ConfigDao) super.getDao();
	}
	
	@Transactional
	public void saveConfigBatch(List<JSONObject> data) throws Exception{
		String sql = "update t_config set value=? where id=?";
		for (JSONObject o : data) {
			String paramId = o.getString("paramId");
			String paramValue =o.getString("paramValue");
			if (CommonUtil.getLongValue(paramId) < 1)
				continue;
			this.getDao().executeUpdateSql(sql, new Object[]{paramValue,paramId});
		}
	}
}